#include <iostream>
#include <string>
#include <stack>
#include <cctype>
#include <unordered_map>
std::unordered_map<char, int> priority = { {'+', 1}, {'-', 1}, {'*', 2}, {'/', 2}, {'(', 0} };
int flag = 1;//标志位
int Float=0;//除法标志位

void calculateTop(std::stack<double>& nums, std::stack<char>& ops)
{
    if (nums.size() < 2 || ops.empty()) return;
    double b = nums.top(); nums.pop();
    double a = nums.top(); nums.pop();
    char op = ops.top(); ops.pop();

    if (op == '+')
    {
        nums.push(a + b);
    }
    else if (op == '-')
    {
        nums.push(a - b);
    }
    else if (op == '*')
    {
        nums.push(a * b);
    }
    else
    {
        if (b == 0)
        {
            flag = -1;
            return;
        }
        nums.push(a / b);
    }
}
double calculate(std::string& str)
{
    std::stack<double> nums;
    std::stack<char> ops;
    double num = 0;
    flag = 1;
    for (int i = 0; i < str.size(); i++)
    {
        char c = str[i];
        if(c=='/') Float=1;
        //处理操作数
        if (isdigit(c))
        {
            num = num * 10 + (c - '0');
            if (i == str.size() - 1 || !isdigit(str[i + 1]))
            {
                nums.push(num);
                num = 0;
            }
            continue;
        }
        //处理操作符
        if (c == '+' || c == '-' || c == '*' || c == '/')
        {
            while (!ops.empty() && priority[ops.top()] >= priority[c])
            {
                calculateTop(nums, ops);
                if (flag == -1)
                    return flag;
            }
            ops.push(c);
        }
        else if (c == '(')
        {
            ops.push(c);
        }
        else if (c == ')')
        {
            while (!ops.empty() && ops.top() != '(')
            {
                calculateTop(nums, ops);
                if (flag == -1)
                    return flag;
            }
            //弹出左括号
            ops.pop();
        }
    }
    //处理剩余的运算符
    while (!ops.empty())
    {
        calculateTop(nums, ops);
        if (flag == -1)
            return flag;
    }
    //最后，nums栈中只剩一个操作数，ops栈为空
    return nums.top();
}
int main()
{
    std::string str;
    while(1)
    {
        flag=1;//标志位，为-1表示输入错误
        std::cout<<"Calculator> ";
        str.clear();
        std::cin>>str;
        double ret=calculate(str);
        if(flag==-1)
        {
            std::cout<<"输入有误，请重新输入"<<std::endl;
        }
        else
        {
            if(Float)
            {
                //算式中出现除法，需要保留小数
                printf("%.1lf\n",ret);
            }
            else
            {
                //算式中没有出现除法，无需保留小数
                printf("%d\n",static_cast<int>(ret));
            }
        }
    }
    return 0;
}